package com.example.syssoft.domain;


import com.example.syssoft.common.entities.LogicEntity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Entity
@Getter
@Setter
@Inheritance
@Where(clause = "is_deleted = 0")
@Table(name = "t_order")
@JsonIgnoreProperties(value = {"handler","hibernateLazyInitializer","fieldHandler"})
public class Order extends LogicEntity {

    @Column
    @Schema(description = "支付状态")
    private Integer payState;

    @Column(columnDefinition = "INT default 0")
    @Schema(description = "商家是否接受订单(0未操作，1接受，2退款)")
    private Integer state;

    @Column
    @Schema(description = "总价")
    private Double totalPrice;

    @OneToMany(mappedBy = "order",fetch = FetchType.LAZY,cascade = CascadeType.ALL)
    @JsonIgnoreProperties(value = {"order","orders","item","lineItems"})
    @Schema(description = "订单明细")
    private List<LineItem> lineItems;

    @ManyToOne(fetch = FetchType.LAZY,cascade = {CascadeType.ALL})
    @JsonIgnoreProperties(value = {"order","orders","item","lineItems"})
    @Schema(description = "隶属用户")
    private Customer customer;

    @ManyToOne(fetch = FetchType.LAZY,cascade = {CascadeType.ALL})
    @JsonIgnoreProperties(value = {"order","orders","item","lineItems"})
    @Schema(description = "隶属商店")
    private Shop shop;

    public void acceptOrder(){
        this.setState(1);
    }

    public void refuseOrder(){
        this.setState(2);
    }

    public void payOrder(){
        this.setPayState(1);
    }
}
